﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiXuLong.Model;

namespace ShiXuLong.Service
{
    public class Order
    {
        ShoesEntities db = new ShoesEntities();
        public List<Model.OrderTest> GetOrder(int limit, int page, int uId, int orderId, out int count)
        {


            var list = from item in db.Orders.Where(p => true)
                       select new OrderTest
                       {
                           Id = item.Id,
                           OrderId = item.OrderId,
                           UserName = item.User.UserName,
                           UserId = item.UserId,
                           PayMoney = item.PayMoney,
                           Freight = item.Freight,
                           PayTime = item.PayTime,
                           SendTime = item.SendTime,
                           EndTime = item.EndTime,
                           CreateTime = item.CreateTime,
                           DataTime = item.DataTime,
                           Stutas = item.Status,
                       };
            if (uId != 0)
            {
                list = list.Where(p => p.UserId == uId);
            }
            if (orderId != 0)
            {
                list = list.Where(p => p.OrderId == orderId);

            }
            count = list.Count();
            return list.ToList();
        }
        /// <summary>
        /// 获取该订单，下面的所有商品，也就是获取订单的订单详情；
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Model.OrderDetail> GetOrderDetail(int id)
        {

            var list = from item in db.OrderItems.Where(p => p.OrderId == id)
                       select new OrderDetail
                       {
                           Id = item.Id,
                           OrderId = item.OrderId,
                           ProductName = item.ProductName,
                           Picurl = item.Picurl,
                           Price = item.Price,
                           Number = item.Number,
                           CreateTime = item.CreateTime,
                           DateTime = item.DateTime,
                           StandardsId = item.StandardsId

                       };
            //if (uId != 0)
            //{
            //    list = list.Where(p => p.UserId == uId);
            //}
            //if (orderId != 0)
            //{
            //    list = list.Where(p => p.OrderId == orderId);

            //}
            //count = list.Count();
            return list.ToList();

        }
        public int SendOrder(int id)
        {
            var list = db.Orders.Where(p => p.Id == id);
            var order = list.SingleOrDefault();
            order.Status = 1;
            var res = db.SaveChanges();
            return res;

        }
       
    }
}
